package com.a3dweijing.wetouch2.Common.RefreshRecycler;

import android.support.v7.widget.LinearLayoutManager;
import android.support.v7.widget.RecyclerView;
import android.util.Log;

import com.a3dweijing.wetouch2.Common.CallBack;

/**
 * Created by Administrator on 2018/3/20.
 */

public class RefreshLinstener extends RecyclerView.OnScrollListener
{
    private RecyclerView recyclerView;
    
    private CallBack callBack;
    
    public RefreshLinstener(CallBack callBack)
    {
        this.callBack = callBack;
    }
    
    @Override
    public void onScrolled(RecyclerView recyclerView, int dx, int dy)
    {
        super.onScrolled(recyclerView, dx, dy);
        if (this.recyclerView == null)
        {
            this.recyclerView = recyclerView;
        }
        LinearLayoutManager manager = (LinearLayoutManager)recyclerView.getLayoutManager();
        // 第一个完全显示的ItemPosition ,角标值
        int friast = manager.findFirstCompletelyVisibleItemPosition();
        // 获取最后一个完全显示的ItemPosition ,角标值
        int lastVisibleItem = manager.findLastCompletelyVisibleItemPosition();
        // 所有条目,数量值
        int totalItemCount = manager.getItemCount();
        if ((lastVisibleItem + 1 == totalItemCount) && friast != 0)
        {
            callBack.doNext(0, null);
        }
    }
    
    @Override
    public void onScrollStateChanged(RecyclerView recyclerView, int newState)
    {
        super.onScrollStateChanged(recyclerView, newState);
        
    }
    
}
